package com.agrm.rabc.service.impl;

import com.agrm.model.rabc.dto.Perm;
import com.agrm.rabc.mapper.PermDao;
import com.agrm.rabc.service.PermService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;


@CacheConfig(cacheNames = "c.s.r.service.impl.PermServiceImpl")
@Service
public class PermServiceImpl implements PermService {
    private PermDao permDao;

    @Autowired
    public void setPermDao(PermDao permDao) {
        this.permDao = permDao;
    }

    @Override
    public Page<Perm> findAll(Perm perm, Page<Perm> page) {
        return permDao.findAll(perm, page);
    }

    @Cacheable(key = "#p0")
    @Override
    public Perm findById(Integer id) {
        return permDao.selectById(id);
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean save(Perm perm) {
        return permDao.insert(perm) == 1;
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean update(Perm perm) {
        return permDao.updateById(perm) == 1;
    }

    @CacheEvict(allEntries = true)
    @Override
    public int deleteByIds(List<Integer> ids) {
        return permDao.deleteByIds(ids);
    }
}
